#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3005;
const int M = 2e4 + 5;
const double eps = 1e-9;
int n, m;
int head[N];
int ver[M], Next[M], tot;
double W[M];
void add(int u, int v, double w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int vis[N];
double dis[N];
bool dfs(int u, double x) {
  vis[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    double w = W[i] - x;
    if (dis[v] > dis[u] + w) {
      dis[v] = dis[u] + w;
      if (vis[v] || dfs(v, x)) return true;
    }
  }
  vis[u] = 0;
  return false;
}
bool check(double x) {
  rep(i, 1, n) vis[i] = 0, dis[i] = 0;
  dis[0] = 0;
  rep(i, 1, n) if (dfs(i, x)) return 1;
  return false;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int u, v;
    double w;
    cin >> u >> v >> w;
    add(u, v, w);
  }
  double l = -1e7, h = 1e7;
  while (l + eps <= h) {
    double mid = (l + h) / 2;
    bool res = check(mid);
    if (res)
      h = mid - eps;  // 存在负环
    else
      l = mid + eps;
  }
  cout << fixed << setprecision(8) << h;
  return 0;
}